package com.example.distillapplication.hardware.protcal;

/**
 * 存储串口协议数据
 */
public class Protocol {
    public final static byte[] selfCheck = new byte[]{(0xFE)-256, 0x01, 0x00, 0x00, 0x00, 0x08, 0x29, (0xC3)-256};//开机自检
    public final static byte[] selfCheckPass = new byte[]{(0xFE)-256, 0x01, 0x01, 0x00, 0x61, (0x9C)-256};//开机自检通过
    public final static byte[] waterLevel = new byte[]{(0xFE)-256, 0x02, 0x00, 0x00, 0x00, 0x08, 0x6D, (0xC3)-256};//水位
    public final static byte[] reboot = new byte[]{(0xFE)-256, 0x0F, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, (0xB1)-256, (0x91)-256};//仪器重启
    public final static byte[] weight = new byte[]{0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00};//单片机称重模块
    public final static byte[] heatTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x00, (0xFF)-256, 0x00, (0xD9)-256, (0xC5)-256};//加热开关打开
    public final static byte[] heatFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x00, 0x00, 0x00,  (0x98)-256, 0x35};//加热开关关闭
    public final static byte[] refrigerationTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x01, (0xFF)-256, 0x00, (0xC9)-256, (0xF5)-256};//制冷开
    public final static byte[] refrigerationFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x01, 0x00, 0x00, (0x88)-256, 0x05};//制冷关
    public final static byte[] valveTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x02, (0xFF)-256, 0x00, 0x39, (0xF5)-256};//开阀
    public final static byte[] valveFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x02, 0x00, 0x00, 0x78, 0x05};//关阀
    public final static byte[] sodaTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x04, (0xFF)-256, 0x00, (0xD9)-256, (0xF4)-256 };//加碱开
    public final static byte[] sodaFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x04, 0x00, 0x00, (0x98)-256, 0x04 };//加碱关
    public final static byte[] lightTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x05, (0xFF)-256, 0x00, (0x88)-256, 0x34};//开灯
    public final static byte[] lightFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x05, 0x00, 0x00, (0xC9)-256, (0xC4)-256};//关灯
    public final static byte[] addWaterTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x06, (0xFF)-256, 0x00, 0x78, 0x34};//加水开
    public final static byte[] addWaterFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x06, 0x00, 0x00, 0x39, (0xC4)-256};//加水开
    public final static byte[] addCoolantTrue = new byte[]{(0xFE)-256, 0x05, 0x00, 0x07, (0xFF)-256, 0x00, 0x29, (0xF4)-256};//加制冷液开
    public final static byte[] addCoolantFalse = new byte[]{(0xFE)-256, 0x05, 0x00, 0x07, 0x00, 0x00, 0x68, 0x04};//加制冷液开


    public static double handleWeight(byte[] weight){
        int weightTemp1 = 0, weightTemp2=0;
        weightTemp1 = weight[3]>=0?weight[3]:(weight[3]+256);
        weightTemp2 = weight[2]>=0?weight[2]:(weight[2]+256);
        double temp = weightTemp2*128 + weightTemp1;
        return temp/100;
    }

    public static double handleTemp(byte[] weight){
        int temperature1=0, temperature2 = 0;
        temperature1 = weight[5]>=0?weight[5]:(weight[5]+256);
        temperature2 = weight[4]>=0?weight[4]:(weight[4]+256);
        double temperature = temperature2*128 + temperature1;
        return temperature/100;
    }
}
